package com.agv.backend.controller;

import com.agv.backend.entity.AjaxResult;
import com.agv.backend.service.SystemCheckService;
import com.agv.backend.service.impl.SystemCheckServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

@RestController
@RequestMapping("/system/check")
@Slf4j
public class SystemCheckController {

    private final SystemCheckService systemCheckService;

    public SystemCheckController(SystemCheckService systemCheckService) {
        this.systemCheckService = systemCheckService;
    }

    @GetMapping("/fs")
    public AjaxResult checkFs() {
        boolean passed = systemCheckService.checkFileSystem();
        return passed
            ? AjaxResult.success("File system check passed")
            : AjaxResult.error("File system check failed");
    }

    @GetMapping("/db")
    public AjaxResult checkDb() {
        boolean passed = systemCheckService.checkDatabaseConnection();
        return passed
            ? AjaxResult.success("Database connection check passed")
            : AjaxResult.error("Database connection check failed");
    }

    @GetMapping("/agv")
    public AjaxResult checkAgv() {
        log.info("checkAgv");
        boolean passed = systemCheckService.checkAgvConnection();
        return passed
            ? AjaxResult.success("AGV connection check passed")
            : AjaxResult.error("AGV connection check failed");
    }

    @GetMapping("/cam")
    public AjaxResult checkCam() {
        boolean passed = systemCheckService.checkCameraConnection();
        return passed
            ? AjaxResult.success("Camera connection check passed")
            : AjaxResult.error("Camera connection check failed");
    }
}